package com.zhaoguang.car.service.impl;

import com.zhaoguang.car.entity.CarImg;
import com.zhaoguang.car.entity.CarInfo;
import com.zhaoguang.car.mapper.CarMapper;
import com.zhaoguang.car.mapper.ShopCarMapper;
import com.zhaoguang.car.service.ShopCarService;
import com.zhaoguang.car.vo.DetailCarVo;
import com.zhaoguang.car.vo.ListCarVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ShopCarServiceImpl implements ShopCarService {

    @Autowired
    ShopCarMapper shopCarMapper;

    @Override
    public int saveCar(CarInfo car) {
        Date date= new Date();
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str = sdf.format(date);
        try {
            Date time = sdf.parse(str);
            car.setAddTime(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        int result = shopCarMapper.saveCar(car);

        return result;
    }

    @Override
    public int deleteCarById(int carId) {
        int result = shopCarMapper.deleteCarById(carId);

        return result;
    }

    @Override
    public int updateCar(CarInfo car) {
        int result = shopCarMapper.updateCar(car);

        return result;
    }

    @Override
    public List<ListCarVo> findShopAllCarById(int shopId) {
        List<ListCarVo> lisCar = shopCarMapper.findShopAllCarById(shopId);

        return lisCar;
    }

    @Override
    public int saveCarTitleImg(CarInfo car) {
        return shopCarMapper.saveCarTitleImg(car);
    }


    @Override
    public int saveCarImg(CarImg img) {
        return shopCarMapper.saveCarImg(img);
    }
}
